package com.woniu.apidriver.service;

import com.alibaba.fastjson.JSONObject;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.remote.ServiceOrderClient;
import com.woniu.internalcommon.remote.ServiceSsePushClient;
import com.woniu.internalcommon.request.OrderRequest;
import com.woniu.internalcommon.request.PushRequest;
import jakarta.annotation.Resource;
import com.woniu.internalcommon.constant.IdentityConstants;
import org.springframework.stereotype.Service;


@Service
public class PayService {
    @Resource
    ServiceSsePushClient serviceSsePushClient;

    @Resource
    ServiceOrderClient serviceOrderClient;
    public ResponseResult pushPayInfo(Long orderId, String price, Long passengerId) {
        // 封装 信息
        JSONObject massage = new JSONObject();
        massage.put("orderId",orderId);
        massage.put("price",price);

        // 修改订单状态
        OrderRequest orderRequest = new OrderRequest();
        orderRequest.setOrderId(orderId);
        serviceOrderClient.pushPayInfo(orderRequest);

        // 推送信息
        PushRequest pushRequest = new PushRequest();
        pushRequest.setUserId(passengerId);
        pushRequest.setIdentity(IdentityConstants.PASSENGER_IDENTITY);
        pushRequest.setContent(massage.toString());
        serviceSsePushClient.push(pushRequest);

        return ResponseResult.success().setMessage("订单已下达，消息推送成功");
    }
}
